package com.itheima.servlet.request;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Arrays;

public class URLDemo {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String username = "张三";

        // 1.使用UTF-8进行URL编码
        String encode = URLEncoder.encode(username, "UTF-8");
        System.out.println("encode = " + encode);

        // 3.使用ISO-8859-1进行URL解码
        String decode = URLDecoder.decode(encode, "ISO-8859-1");
        System.out.println("decode = " + decode);

        // 4.转换为字节数据,使用ISO-8859-1编码
        String encode1 = URLEncoder.encode(decode, "ISO-8859-1");
        System.out.println("encode1 = " + encode1);

        // 5.将字节数组转为字符串，使用UTF-8解码
        String decode1 = URLDecoder.decode(encode1, "UTF-8");
        System.out.println("decode1 = " + decode1);
    }
}
